package gui.cliente;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.border.BevelBorder;
import javax.swing.border.MatteBorder;

import java.awt.Color;
import java.awt.Panel;

import javax.swing.JSplitPane;
import javax.swing.JDesktopPane;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import java.awt.Component;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.UIManager;

import classes.Cliente;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JRadioButton;

import fachada.Fachada;

public class FormCliente extends JFrame {

	private JPanel contentPane;
	private JTextField txtNome;
	private JTextField txtCpf;
	private JTextField txtCompl;
	private JTextField txtNumero;
	private JTextField txtCep;
	private JTextField txtCidade;
	private JTextField txtBairro;
	private JTextField txtLogradouro;
	private JTextField txtCelular;
	private JTextField txtResidencial;
	private JTextField txtEmail;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FormCliente frame = new FormCliente();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FormCliente() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 728, 373);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("Funcion\u00E1rios");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("Cadastrar");
		mnNewMenu.add(mntmNewMenuItem);
		
		JMenuItem mntmNewMenuItem_2 = new JMenuItem("Remover ");
		mnNewMenu.add(mntmNewMenuItem_2);
		
		JMenuItem mntmNewMenuItem_3 = new JMenuItem("Buscar");
		mnNewMenu.add(mntmNewMenuItem_3);
		
		JMenu mnNewMenu_1 = new JMenu("Clientes");
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmNewMenuItem_4 = new JMenuItem("Cadastrar Novo");
		mnNewMenu_1.add(mntmNewMenuItem_4);
		
		JMenuItem mntmNewMenuItem_6 = new JMenuItem("Remover");
		mnNewMenu_1.add(mntmNewMenuItem_6);
		
		JMenuItem mntmNewMenuItem_7 = new JMenuItem("Buscar");
		mnNewMenu_1.add(mntmNewMenuItem_7);
		contentPane = new JPanel();
		contentPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Nome: ");
		lblNewLabel.setBounds(39, 51, 46, 14);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Cpf: ");
		lblNewLabel_1.setBounds(39, 91, 46, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Sexo");
		lblNewLabel_2.setBounds(39, 133, 46, 14);
		contentPane.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("N\u00FAmero");
		lblNewLabel_3.setBounds(262, 51, 46, 14);
		contentPane.add(lblNewLabel_3);
		
		JLabel lblNewLabel_5 = new JLabel("Cep: ");
		lblNewLabel_5.setBounds(262, 91, 46, 14);
		contentPane.add(lblNewLabel_5);
		
		txtNome = new JTextField();
		txtNome.setBounds(95, 48, 86, 20);
		contentPane.add(txtNome);
		txtNome.setColumns(10);
		
		txtCpf = new JTextField();
		txtCpf.setBounds(95, 88, 86, 20);
		contentPane.add(txtCpf);
		txtCpf.setColumns(10);
		
		txtCompl = new JTextField();
		txtCompl.setBounds(335, 130, 86, 20);
		contentPane.add(txtCompl);
		txtCompl.setColumns(10);
		
		txtNumero = new JTextField();
		txtNumero.setBounds(335, 48, 52, 20);
		contentPane.add(txtNumero);
		txtNumero.setColumns(10);
		
		txtCep = new JTextField();
		txtCep.setBounds(335, 88, 86, 20);
		contentPane.add(txtCep);
		txtCep.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("Compl: ");
		lblNewLabel_4.setBounds(262, 133, 46, 14);
		contentPane.add(lblNewLabel_4);
		
		JLabel lblNewLabel_7 = new JLabel("Bairro: ");
		lblNewLabel_7.setBounds(431, 91, 46, 14);
		contentPane.add(lblNewLabel_7);
		
		JLabel lblNewLabel_8 = new JLabel("Logradouro: ");
		lblNewLabel_8.setBounds(431, 133, 86, 14);
		contentPane.add(lblNewLabel_8);
		
		txtCidade = new JTextField();
		txtCidade.setBounds(469, 48, 193, 20);
		contentPane.add(txtCidade);
		txtCidade.setColumns(10);
		
		txtBairro = new JTextField();
		txtBairro.setBounds(497, 88, 165, 20);
		contentPane.add(txtBairro);
		txtBairro.setColumns(10);
		
		txtLogradouro = new JTextField();
		txtLogradouro.setBounds(522, 130, 140, 20);
		contentPane.add(txtLogradouro);
		txtLogradouro.setColumns(10);
		
		JButton btnNewButton = new JButton("Cadastrar");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				try {
					Cliente cliente = new Cliente();
					cliente.setNome(txtNome.getText());
					cliente.setCpf(txtCpf.getText());
					cliente.getEndereco().setBairro(txtBairro.getText());
					cliente.getEndereco().setCep(txtCep.getText());
					cliente.getEndereco().setCidade(txtCidade.getText());
					cliente.getEndereco().setComplemento(txtCompl.getText());
					cliente.getEndereco().setLogradouro(txtLogradouro.getText());
					cliente.getEndereco().setNumero(Integer.parseInt(txtNumero.getText()));
					cliente.getContato().setEmail(txtEmail.getText());
					cliente.getContato().setTel_celular(txtCelular.getText());
					cliente.getContato().setTel_residencial(txtResidencial.getText());
					cliente.setSexo("Feminino");
					
					Fachada.getInstance().inserirCliente(cliente);
					
					JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso");
				} catch (Exception e) {
					JOptionPane.showMessageDialog(null, "Deu merda!");
				}
					
				
				
			}
		});
		btnNewButton.setBounds(410, 280, 116, 23);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("Cancelar");
		btnNewButton_1.setBounds(576, 280, 89, 23);
		contentPane.add(btnNewButton_1);
		
		JLabel lblNewLabel_9 = new JLabel("Tel. Celular: ");
		lblNewLabel_9.setBounds(39, 203, 86, 14);
		contentPane.add(lblNewLabel_9);
		
		JLabel lblNewLabel_10 = new JLabel("Tel. Residencial: ");
		lblNewLabel_10.setBounds(39, 235, 121, 14);
		contentPane.add(lblNewLabel_10);
		
		JLabel lblNewLabel_11 = new JLabel("Email: ");
		lblNewLabel_11.setBounds(39, 269, 46, 14);
		contentPane.add(lblNewLabel_11);
		
		txtCelular = new JTextField();
		txtCelular.setBounds(135, 200, 154, 20);
		contentPane.add(txtCelular);
		txtCelular.setColumns(10);
		
		txtResidencial = new JTextField();
		txtResidencial.setBounds(135, 232, 154, 20);
		contentPane.add(txtResidencial);
		txtResidencial.setColumns(10);
		
		txtEmail = new JTextField();
		txtEmail.setBounds(135, 266, 154, 20);
		contentPane.add(txtEmail);
		txtEmail.setColumns(10);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Contato", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setBounds(28, 184, 280, 117);
		contentPane.add(panel_2);
		
		JLabel lblNewLabel_6 = new JLabel("Cidade: ");
		lblNewLabel_6.setBounds(397, 51, 40, 14);
		contentPane.add(lblNewLabel_6);
		
		JRadioButton rdbtnF = new JRadioButton("F");
		rdbtnF.setBounds(91, 129, 40, 23);
		contentPane.add(rdbtnF);
		
		JRadioButton rdbtnM = new JRadioButton("M");
		rdbtnM.setBounds(147, 129, 34, 23);
		contentPane.add(rdbtnM);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Pessoal", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(28, 22, 193, 151);
		contentPane.add(panel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(243, 22, 446, 151);
		contentPane.add(panel_1);
		panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Endereco", TitledBorder.LEADING, TitledBorder.TOP, null, null));
	}
}
